home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / The-Disk-Scripts / mntdisk < prev    next >
Encoding:
Text File  |  1996-03-13  |  5.9 KB  |  233 lines

  1. #!/bin/sh
  2.  
  3. # AUTHOR:  Timothy J. Luoma <luomat@capitalist.princeton.edu>
  4. #
  5. # DATE:    14 March 1996
  6. #
  7. # WARNING: USE ENTIRELY AT YOUR OWN RISK
  8. #
  9. # PURPOSE: easily mount floppy disks and CDs
  10. #
  11. # TESTED UNDER: NeXTStep 3.2 on my NeXTStation
  12. #
  13. #
  14. # USAGE NOTES: This script has two modes:
  15. #
  16. # LINE MODE: takes two arguments, one the type of disk, the other
  17. #    is the disk label.
  18. # INTERACTIVE MODE: if there are not two arguments, then this script
  19. #    will enter interactive mode
  20. #
  21. # NOTE: if the first argument is the word 'help' then a usage
  22. #    summary is printed, and then the script exits.
  23. #
  24. # LINE MODE allows you to bypass the interactive questions, but it is
  25. #    still required that you confirm the mounting action.
  26. #
  27. # NOTES:
  28. # I spent a lot of time on this, and my screw-ups caused more than
  29. # one 'fsck' on reboot, and at least 2 panics.  This is not something
  30. # to just toy around with.  However, I think this script helps take
  31. # some of the guesswork out.  When in doubt, use the interactive
  32. # mode.
  33. #
  34. # The mount commands only work as 'root' I believe, so if this script is
  35. # not run as 'root' a warning pops up and asks if you still want to 
  36. # continue.
  37. #
  38. # If the script goes to run a mount command, it prints the command
  39. # so you can see exactly what it is doing.
  40. #
  41. # KNOWN BUGS/Possible problems: 
  42. # 1) Well, I don't consider this a bug, but if you
  43. #    enter something which the program doesn't understand,
  44. #    it exits.  I try to tell you what caused it to
  45. #    choke, where possible.
  46. #
  47. # 2) Sometimes the disk shows up in the Workspace and the 'Disk->Eject'
  48. #    menu item remains greyed out.  This does not follow any type of 
  49. #    pattern, as far as I could tell.  Sometimes the same disk would work
  50. #    once, and then it wouldn't work the next time.
  51. #
  52. #    Workaround: umount by hand and then use 'disk -e'; or get my other
  53. #                script called 'eject.sh' which will do this when run
  54. #                as root.
  55. #
  56. # 3) FOR CDs: This was tested with two types of CDs: NeXT CDs and Non-NeXT
  57. #    CDs.  The difference is simple.  If you have a NeXT CD mounted 
  58. #    properly, 'mount -p' shows the filesystem as '4.3'.  A Non-NeXT
  59. #    CD shows up as 'cfs'.  Any other types will probably make this
  60. #    script choke and die.
  61. #
  62. # 4) must run as root to use 'mount'
  63. #
  64. # 5) TESTED ONLY ON MY NeXTStation running 3.2
  65.  
  66.  
  67. name=`basename $0`
  68.  
  69. ############################################################
  70. # DEFINE MOUNT DEVICES
  71. #
  72. # device for NeXT-formatted floppies
  73. nextflop=/dev/fd0a
  74.  
  75. # device for DOS or Mac formatted floppies
  76. altflop=/dev/rfd0b
  77.  
  78. # device for NeXT CDs
  79. nextcd=/dev/sd2a
  80.  
  81. # device for NON-NeXT CD
  82. altcd=/dev/rsd2h
  83. ############################################################
  84.  
  85. if [ "$1" = "help" ]
  86. then
  87.  
  88. echo "Usage: $name disktype name"
  89. echo "    where 'disktype' is ONE of these:"
  90. echo "    mac-floppy   dos-floppy   next-floppy   next-cd    nonnext-cd "
  91. echo "    and 'name' is the disk label"
  92. exit 0
  93.  
  94. fi
  95.  
  96. USER=`whoami`
  97.  
  98. if [ "$USER" != "root" ]
  99. then
  100.     echo "$name: only works when run as root."
  101.     echo -n "Continue? [y/N] "
  102.     stty cbreak
  103.     continue=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  104.     stty -cbreak
  105.     
  106.     if [ "$continue" != "y" ]
  107.     then
  108.         exit 0
  109.     else
  110.         echo " "
  111.     fi
  112.  
  113. fi
  114.  
  115. if [ $# = "2" ]            # if there are two arguments
  116. then
  117.     disktype=$1    # floppy (mac/dos/next) or CD (next/nonnext)
  118.     rawmount=$2    # /something
  119.     
  120. else                # if there are not two arguments
  121.  
  122.     echo -n "$name: CD or floppy disk? (PRESS: c or f) "
  123.     stty cbreak
  124.     disktype=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  125.     stty -cbreak
  126.     echo ""
  127.     
  128.     case $disktype in    # check either for floppy disk or CD
  129.         c)         # if it is a CD
  130.             echo -n "Is this a NeXT CD? [y/N] "
  131.             stty cbreak
  132.             cdtype=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  133.             stty -cbreak
  134.             
  135.             case $cdtype in
  136.             y|Y) disktype=next-cd
  137.             ;; 
  138.             *)   disktype=nonnext-cd
  139.             ;;
  140.             esac
  141.         ;;
  142.         f)         # if it is a floppy disk
  143.              echo -n "Is this a Mac, DOS, or NeXT floppy disk? (m|d|n) "
  144.         stty cbreak
  145.         floppytype=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  146.         stty -cbreak
  147.             case $floppytype in
  148.             m|M) disktype=mac-floppy
  149.             ;;
  150.             d|D) disktype=dos-floppy
  151.             ;;
  152.             n|N) disktype=next-floppy
  153.             ;;
  154.             *) echo "$name: Unknown disktype, exiting."
  155.                exit 0
  156.             ;;
  157.             
  158.             esac
  159.            
  160.         ;;
  161.         *) echo "$name: unknown disktype <$disktype>"
  162.            exit 0
  163.         ;;
  164.     esac
  165.  
  166.     echo " "
  167.     echo -n "$name: Where should it be mounted? "
  168.     read rawmount
  169.  
  170. fi
  171.  
  172. # Ok, no matter how many arguments there are,
  173. # check what type of disk, what type of filesystem, and where 
  174. # it should be mounted.
  175.  
  176.     # Big trouble here.  There needs to be a '/' at the beginning
  177.     # of the mount point.  But is it good programming to depend
  178.     # on the user to remember/know that?  Probably not.  But if 
  179.     # we assume they WON'T put a '/' and they do, well that causes
  180.     # all sorts of hell.  So we take the name the input, send it
  181.     # through 'tr' and just strip away any '/' and put it in there
  182.     # later.  And we might as well strip away any spaces while
  183.     # we are at it and replace them by '_' 
  184. mtlocation=`echo $rawmount | tr -d "/" | tr -s ' ' '_'`
  185.  
  186.  
  187. echo "$name: About to try to mount a $disktype at /$mtlocation"
  188. echo -n "    Is this correct? (Enter 'y' to continue) "
  189. read verify
  190.  
  191. if [ "$verify" != "y" ]
  192. then
  193.     echo "$name: Did not get confirmation, exiting."
  194.     exit 0
  195. fi
  196.  
  197. case $disktype in
  198.     mac-floppy)
  199.        echo "mount -t macintosh -o rw,removable $altflop /$mtlocation"
  200.          mount -t macintosh -o rw,removable "$altflop" /"$mtlocation"
  201.     ;;
  202.     
  203.     dos-floppy)
  204.       echo "mount -t dos -o rw,removable $altflop /$mtlocation"
  205.         mount -t dos -o rw,removable "$altflop" "/$mtlocation"
  206.  
  207.     ;;
  208.     
  209.     next-floppy)
  210.       echo "mount -t 4.3 -o rw,removable $nextflop /$mtlocation"
  211.         mount -t 4.3 -o rw,removable "$nextflop" /"$mtlocation"
  212.         
  213.     ;;
  214.     
  215.     next-cd)
  216.       echo "mount -t 4.3 -o ro,removable $nextcd /$mtlocation"
  217.         mount -t 4.3 -o ro,removable $nextcd /"$mtlocation" 
  218.     ;;
  219.     
  220.     nonnext-cd)
  221.         echo "mount -t cfs -o ro,removable $altcd /$mtlocation"
  222.         mount -t cfs -o ro,removable $altcd /"$mtlocation"
  223.     ;;
  224.     
  225.     *) echo "$name: Unknown disktype <$disktype>, exiting."
  226.        exit 0
  227.     ;;
  228.  
  229. esac
  230.  
  231. exit 0
  232.  
  233.